import React from 'react';

import { BrowserRouter as Router, Route, Link, Switch, Redirect } from 'react-router-dom';

import ProductList from 'page/product/index/index.jsx';
import ProductSave from 'page/product/index/save.jsx';
import ProductDetail from 'page/product/index/detail.jsx';
import CategoryList from 'page/product/category/index.jsx';
import CategoryAdd from 'page/product/category/add.jsx';


class ProductRouter extends React.Component {
    constructor(props) {
        super(props);
    }

    render() {
        return (
            <Switch>
                <Route path="/product/index" component={ProductList}></Route>
                <Route path="/product/detail/:pid" component={ProductDetail}></Route>
                <Route path="/product/detail/:pid" component={ProductDetail}></Route>
                <Route path="/product-category/index/:categoryId?" component={CategoryList}></Route>
                <Route path="/product-category/add" component={CategoryAdd}></Route>
                {/* 上面一行这个问号表示这参数是可选的，即有没有pid这个参数都是渲染 ProductSave 组件 */}
                <Redirect exact from='/product' to='/product/index'></Redirect>
                <Redirect exact from='/product-category' to='/product-category/index'></Redirect>
            </Switch>
        );
    }
}

export default ProductRouter